package com.woniu.common.advice;


import com.woniu.common.entity.Result;
import com.woniu.common.exception.MallException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 */
@RestControllerAdvice
@Slf4j
public class DefaultExceptionAdvice {

    @ExceptionHandler(MallException.class)
    public Result mallExceptionHandler(MallException mallException){
        mallException.printStackTrace();
        //打印异常
        log.debug("系统抛出了自定义异常:{}",mallException.getMessage());
        //将异常保存日志
        //响应数据
        return Result.error(mallException.getResultCode().getCode(),mallException.getResultCode().getMessage());

    }

    @ExceptionHandler(Exception.class)
    public Result mallExceptionHandler(Exception exception){
        exception.printStackTrace();
        //打印异常
        log.debug("系统抛出了自定义异常",exception.getMessage());
        return Result.error();
    }
}
